﻿using pingjia.bll;
using PJTY.dal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class views_admin_Ask1 : System.Web.UI.Page
{
    private ConsumerService consumerService = new ConsumerService();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["username"] != null)
            {
                var consumer = consumerService.GetConsumerInformation(Session["username"].ToString());
                if (consumer != null)
                {
                    TextBox2.Text = consumer.ConsumerID.ToString(); // 用户编号
                    TextBox3.Text = consumer.ConsumerName; // 用户名称
                    TextBox1.Text = consumer.ConsumerAge.ToString(); // 用户年龄
                    TextBox7.Text = DateTime.Now.ToString();
                }
            }

            string productIDStr = Request.QueryString["ProductID"];
            int productID;
            if (!string.IsNullOrEmpty(productIDStr) && int.TryParse(productIDStr, out productID))
            {
                var product = consumerService.GetProductById(productID);
                if (product != null)
                {
                    TextBoxid.Text = product.ProductID.ToString();
                    TextBoxname.Text = product.ProductName;
                }
            }
        }
    }

    protected void Unnamed2_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            consumerService.resume(
                int.Parse(TextBox2.Text.Trim()),
                TextBox3.Text.Trim(),
                int.Parse(TextBox1.Text.Trim()),
                int.Parse(TextBoxid.Text.Trim()),
                TextBoxname.Text.Trim(),
                TextBox6.Text.Trim(),
                DateTime.Parse(TextBox7.Text.Trim())
            );

            string script = "alert('提交成功！');";
            ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true);
        }
    }

    protected void Unnamed1_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox3.Text = "";
        TextBox6.Text = "";
        TextBox7.Text = "";
    }

    protected void Unnamed3_Click(object sender, EventArgs e)
    {
        Response.Redirect("Ask.aspx");
    }
}